/*
 * TrackComparator.java
 */
package behavior_analysis_model;

import java.util.Comparator;

/**
 * Custom comparator for Track objects.
 * 
 * @author Sean Brown
 * @version 11/10/2012
 */
public class TrackComparator implements Comparator<Object> {

	/**
	 * Overridden compare method, which compares two Track
	 * objects and determines which one was recorded first.
	 * 
	 * @param track_1 First Track.
	 * @param track_2 Second Track.
	 * @returns int value for which track is ordered first.
	 */
	@Override
	public int compare(Object track_1, Object track_2) {
		if (track_1 == null || track_2 == null || !(track_1 instanceof Track) || !(track_2 instanceof Track)) {
			throw new IllegalArgumentException("Invalid objects for comparison.");
		}
		final long result = ((Track)track_1).getDateTime() - ((Track)track_2).getDateTime();
		if (result > 0.0) {
			return 1;
		} else if (result < 0.0) {
			return -1;
		} else {
			return 0;
		}
	}
	
}
